package com.miao.UserClass;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;


public class MyCondition2 implements Condition {


    /**
    * Description:
    *
     * ConditionContext: 上下文环境
     * AnnotatedTypeMetadata：标注了Conditional的类信息
    */
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {

        //看容器里面是否包含某个Bean，包含 Car 时候，再注册Boy2

        //获取Bean注册器，
        BeanDefinitionRegistry registry = context.getRegistry();
        //判断容器中是否有某个Bean
        if(registry.containsBeanDefinition("car")){
            return true;
        }
        return false;
    }
}
